** Data reading and variable selection from raw data
** International Social Survey Panel (ISSP), HUN 1986


** 01. Reading data **

cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/
numlabel, add


** 02. Constructing year and country variables **

ge year=1986
lab var year "survey year"

ge country=348
lab var country "ISO country code"
//Hungary: 348 (ISO Country Codes) 



** 03. ID variables **

ge pid=v2
lab var pid "person id"

ge cid=v3
lab var cid "country id"
keep if cid==6


** 04. Basic Demographics (Sex and Age/birth year) **

ge sex=v81
lab var sex "sex"
lab def sex 1 "male" 2 "female"
lab val sex sex

ge age=v80
lab var age "age"

ge birthyr=year-age
lab var birthyr "year of birth"


** 05. Siblings **

ge nbro=v16 

ge nsis=v12
* q19_1 and q19_2 include respondent

ge nsibs=nbro+nsis
lab def nsibs 10 "Ten or more"
lab val nsibs nsibs
lab var nsibs "number of siblings aged 18 or older"

lab var nbro "number of brothers aged 18 or older"
lab def nbro 05 "Five or more"
lab val nbro nbro
lab var nsis "number of sisters aged 18 or older"
lab def nsis 05 "Five or more"
lab val nsis nsis


** 06. Own education **

ge schooling=v85
lab var schooling " Yeas in school, recoded according to duration of compulsory education"

ge educ=v86
lab var educ "highest level of education completed"
lab def educ 1 "none" 2 "Incomplete primary" 3 "Primary completed" 4 "Incomplete secondary" 5 "Secondary completed" 7 "University"
lab val educ educ


** 07. Parents' education: Father and/or Mother **

//no information about parents' education in this dataset


** 08. Own occupation **

ge occ=v73
ge empstat=v72
lab var occ "present occupation"
lab var empstat "employment status"

lab def empstat 1 "unemployed" 2 "employed"
lab val empstat empstat



** 09. Parents' occupation **

ge faocc=v102
lab var faocc "father's occupation"


** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text


** Data reading and variable selection from raw data
** International Social Survey Panel, HUN 1986

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs nbro nsis , d

** R's Own Education **
tab1 schooling educ 

** R's Own Occupation **
tab1 occ empstat 

** Parental Occupation **
tab1 faocc 

log close

** 11. Keep the identified variables only

keep year country cid pid sex age birthyr ///
	 nbro nsis nsibs ///
	 schooling educ ///
	 occ empstat faocc



** 12. Save the Data File **

saveold /*insert you work directory here*/, replace


** 13. Homoginising education **
** Own Education **
rename educ educ_cat
rename schooling educ_yrs
//code missing variables
replace educ_yrs=. if educ_yrs==-2 

ge educ_ISCED=020 if educ_yrs<4
replace educ_ISCED=100 if educ_yrs==4 
replace educ_ISCED=244 if educ_yrs>4 & educ_yrs<=9
replace educ_ISCED=354 if educ_yrs>=10 & educ_yrs<=12 
replace educ_ISCED=454 if educ_yrs>12 & educ_yrs<=14
replace educ_ISCED=554 if educ_yrs>14 & educ_yrs<=16
replace educ_ISCED=766 if educ_yrs>16 & educ_yrs<=19
replace educ_ISCED=864 if educ_yrs==20
lab var educ_ISCED "respondent highest education in ISCED code"

** Parents Education **

//parents education not available


** 14. Homoginising sibling **
//cutoff
ge nsibs_flag=10
ge nbro_flag=5
ge nsis_flag=5
lab var nsibs_flag "cutoff of total number of siblings"
lab var nbro_flag "cutoff of total number of brothers"
lab var nsis_flag "cutoff of total number of sisters"


** 15. Tab Education and Sibling Variables **
tab1 sex age birthyr
tab1 educ_cat educ_yrs 
tab1 nsibs nbro nsis nsibs_flag nbro_flag nsis_flag


** 16. Save the Data File **

saveold /*insert you work directory here*/, replace

